	<?php
		$ordered_flags = array();
		foreach($allflags as $row):
			$ordered_flags[$row->parent][$row->id] = $row->name_en. " - " .$row->name_ar;
		endforeach;

		function check_slected_tag($selected_flags,$id)
		{
			if(isset($selected_flags) && is_array($selected_flags))
			foreach($selected_flags as $row)
				if($row->flag_id == $id)
					return TRUE;
			
			return False;
		}
		
		function build_tree($all_flags_array, $start_with=0){
			echo "<ul class='block-list'>";
			foreach ($all_flags_array[$start_with] as $index=>$value){
				
				echo "<li id='li_{$index}'>";
				echo '<label for="flag_'.$index.'"> '.$value;
				echo '</label>';
				
				echo "<div class='d_{$index}' style='padding-left:20px;margin-left:20px'>";
					
					if(isset($all_flags_array[$index]) && is_array($all_flags_array[$index])){
						build_tree($all_flags_array,$index);
					}
				echo "</div>";
				echo "</li>";
				
			}
			echo "</ul>";
		}
		
		?>
		
	<html>
		<head>
			<style>
			li {font-family:'Droid Sans Arabic'; font-size:13px;}
			ul {padding-bottom:10px; margin-top:10px;margin-bottom:10px;}
			</style>
			
		</head>
		
		<body>
			<div id="accordion">
				<?php build_tree($ordered_flags,0);?>
			</div>
		</body>
	
	</html>	
	
	
			
			
			
			
			
			
